package com.atguigu.educms.service.impl;

import com.atguigu.common.cron.bean.PageListBean;
import com.atguigu.educms.entity.CmsLinks;
import com.atguigu.educms.mapper.CmsLinksMapper;
import com.atguigu.educms.service.CmsLinksService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 * 友情链接 服务实现类
 * </p>
 *
 * @author Panghl
 * @since 2021-03-11
 */
@Service
public class CmsLinksServiceImpl extends ServiceImpl<CmsLinksMapper, CmsLinks> implements CmsLinksService {

    @Override
    public List<CmsLinks> getAllLinks() {
        QueryWrapper<CmsLinks> qw = new QueryWrapper<>();
        qw.orderByAsc("id");
        qw.last("limit 5");
        return baseMapper.selectList(qw);
    }

    @Override
    public PageListBean pageLinksConditions(Integer pageNo, Integer pageSize, CmsLinks cmsLinks) {
        Page<CmsLinks> pageParam = new Page<>(pageNo,pageSize);
        if (!StringUtils.isEmpty(cmsLinks)){
            QueryWrapper<CmsLinks> qw = new QueryWrapper<>();
            qw.like(!StringUtils.isEmpty(cmsLinks.getLinkName()),"link_name",cmsLinks.getLinkName());
            baseMapper.selectPage(pageParam,qw);
        }else {
            baseMapper.selectPage(pageParam,null);
        }
        return new PageListBean((int)pageParam.getTotal(),pageParam.getRecords());
    }
}
